﻿// -----------------------------------------------------------------------
// <copyright file="MainMask.cs" company="Abyssalsoft">
// TODO: Update copyright text.
// </copyright>
// -----------------------------------------------------------------------

namespace Gui.Player.Main
{
    using System;
    using System.Collections.Generic;
    using System.ComponentModel;
    using System.Data;
    using System.Drawing;
    using System.Runtime.InteropServices;
    using System.Text;
    using System.Windows.Forms;
    using Metal.Player.Main;
    using Core.Player;

    /// <summary>
    /// Audio mask
    /// </summary>
    public partial class MainMask : Gui.BaseMask.BaseMask, IMainView
    {
        #region Members

        /// <summary> Represents the controller for this mask </summary>
        private MainController controller;

        #endregion

        #region Constructor

        /// <summary>
        /// Initializes a new instance of the MainMask class.
        /// </summary>
        public MainMask()
        {
            try
            {
                this.InitializeComponent();

                this.controller = new MainController(this);

                this.ApplyTheme();

                // Subscribe to on media load event (used to switch between audio / video style)
                Core.Player.Events.Instance.BeforeOpen += new EventHandler(OnBeforeOpenFile);
            }
            catch (Exception ex)
            {
                Metal.User.UserMessage.ShowError(ex);
            }
        }

        #endregion

        #region Properties

        /// <summary>
        /// Sets the position bar the maximum value
        /// </summary>
        public int TrackBarMaximumValue
        {
            set
            {
                if (GetControl("TrackBar") != null)
                {
                    (GetControl("TrackBar") as Gui.Controls.MetalSlider).Maximum = value;
                }
            }
        }

        /// <summary>
        /// Sets the position bar value
        /// </summary>
        public int TrackBarValue
        {
            set
            {
                if (GetControl("TrackBar") != null)
                {
                    (GetControl("TrackBar") as Gui.Controls.MetalSlider).Value = value;
                }
            }
        }

        /// <summary>
        /// Sets the volume value
        /// </summary>
        public int Volume
        {
            set
            {
                if (GetControl("Volume") != null)
                {
                    (GetControl("Volume") as Gui.Controls.MetalSlider).Value = value;
                }
            }
        }

        /// <summary>
        /// Sets a value indicating whether the controls of this form are shown
        /// </summary>
        public bool HideControlsFullScreen
        {
            set
            {
                // Not used for audio view
            }
        }

        #endregion

        /// <summary>
        /// Switch to video style if opened file is a video format
        /// </summary>
        /// <param name="sender">Object sender</param>
        /// <param name="e">Event args</param>
        private void OnBeforeOpenFile(object sender, EventArgs e)
        {
            try
            {
                if (this.Visible == false)
                {
                    return;
                }

                this.controller.SetCurrentView(this);
            }
            catch (Exception ex)
            {
                Metal.User.UserMessage.ShowError(ex);
            }
        }
    }
}
